<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/qq/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/gonglue/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["id"], "id", "");
	$g_cgival["id"] = intval($g_cgival["id"]);
	
}



function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "mblog";
	
	
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
	$id = $g_cgival["id"];
	
	$db_gonglue = new db_gonglue();
	$item = $db_gonglue->get_item_by_id($id);
	if($item["topic_id"])
	{
		$topic_info = $db_mblog_cron_topic_tag->get_mblog_cron_topic_tag_item_by_id($item["topic_id"]);
		$item["topic"] = $topic_info["topic"];
		if($item["topic_id"] != $config["current_site_id"])
		{
			header("Location:http://".$config["domain_url"][$item["topic_id"]].$_SERVER["SCRIPT_URL"]);
		}
	}
	
	
	$g_show["item"] = $item;
	
	$db_mblog_pic_content = new db_mblog_pic_content();
	
	
	
	$big_list = $db_gonglue->get_gonglue_list_biger_by_topic_and_create_time(1,10,$item["topic_id"],$item["create_time"]);
	foreach($big_list as $key => $value)
	{
		$big_list[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($value["title"],36);
		if($value["id"] == $id)
		{
			unset($big_list[$key]);
			continue;
		}
	}
	$big_list = array_values($big_list);
		
	$small_list = $db_gonglue->get_gonglue_list_smaller_by_topic_and_create_time(1,10,$item["topic_id"],$item["create_time"]);
	foreach($small_list as $key => $value)
	{
		$small_list[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($value["title"],36);
		if($value["id"] == $id)
		{
			unset($small_list[$key]);
			continue;
		}
	}
	$small_list = array_values($small_list);
	
	if(count($big_list)<5)
	{
		
		$big_list = array_merge($big_list,array_slice($small_list,4));
	}
	
	if(count($small_list)<5)
	{
		$small_list = array_merge($small_list,array_slice($big_list,4));
	}
	
	$big_list= array_slice($big_list,0,5);
	$small_list= array_slice($small_list,0,5);
	
	$g_show["small_list"] = $small_list;
	$g_show["big_list"] = $big_list;
	
	
	$current_site_name = $config["current_site_name"];
	$page_title=  string_utf8::substr_utf8_cn_v2($item["title"],40)."_{$current_site_name}攻略_游戏美图";
	$g_show["page_title"] =$page_title;
	$g_show["page_keywords"]  = "{$current_site_name},{$current_site_name}攻略,{$current_site_name}资讯,{$current_site_name}新闻,{$current_site_name}视频攻略";
	
	if($config["site_alias"][$config["current_site_id"]])
	{
		foreach($config["site_alias"][$config["current_site_id"]] as $value)
		{
			$g_show["page_keywords"]  .= ",{$value},{$value}攻略,{$value}资讯,{$value}新闻,{$value}视频攻略";
		
		}
	}
		
	
	$g_show["page_desc"] = $item["title"];
	
	
	
	$g_show["order"] = $order;
	$g_show["topic_id"] = $topic_id;
	$g_show["show_type"] = $show_type;
	$g_show["pubu_show_type"] = "video";
	
	$daohang[] = "<a href='/'>首页</a>";
	$daohang[] = "<a href='/gonglue/'>{$config["current_site_name"]}攻略</a>";
	if($item["content_type"]==1)$daohang[] = "<a href='/gonglue/index_1.html'>{$config["current_site_name"]}视频攻略</a>";
	$daohang[] = "详细";
	$g_show["daohang"] =join(" <i>&gt;</i> ",$daohang);
	
/*	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;*/
	
	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;
	
	
	
		//右侧推荐
		$db_gonglue = new db_gonglue();
		$gonglue_list1 = $db_gonglue->get_list_order_by_time(1,6,0,$config["current_site_id"],"",$item["create_time"]);
		$gonglue_list2 = $db_gonglue->get_list_order_by_time(1,6,1,$config["current_site_id"],"",$item["create_time"]);
		foreach($gonglue_list1 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list1[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list1[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list1[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list1[$key]["title"],36);
		}
		
		foreach($gonglue_list2 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list2[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list2[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list2[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list2[$key]["title"],36);
		}
			
		
		$g_show["gonglue_list1"] = $gonglue_list1;
		$g_show["gonglue_list2"] = $gonglue_list2;
		
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$meinv_tuijian_list = $db_mblog_meinv_content->get_mblog_meinv_list_by_tuijian(1,9,"",$item["create_time"]);
		foreach($meinv_tuijian_list as $key => $value)
		{
			$meinv_tuijian_list[$key]["pic_small"]  = str_replace("/bmiddle/","/thumb150/",$meinv_tuijian_list[$key]["pic"]);
		}
		
		$g_show["meinv_tuijian_list"] = $meinv_tuijian_list;
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	$g_show["hide_shadow"] = true;
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("gonglue/detail.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

